import Router from 'koa-router'

const { noticeIdExist } = require('../middleware/notice.middleware')
const { auth } = require('../middleware/auth.middleware')
const { getNotices, getNoticesByKeyword, getNoticeById, addNotice, updateNotice, deleteNotice } = require('../controller/notice.controller') 
const router = new Router({ prefix: '/notices' })

/**
 * 公告管理模块
 * @description notice
 */
router.get('/', getNotices) // 获取所有公告(分页可选)
router.get('/byKeyword', getNoticesByKeyword) // 根据关键词搜索公告(分页可选)
router.get('/:id', getNoticeById) // 根据id获取公告
router.post('/', auth, addNotice) // 添加公告
router.put('/:id', auth, noticeIdExist, updateNotice) // 更新公告
router.delete('/:id', auth, noticeIdExist, deleteNotice) // 删除公告

module.exports = router